<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-everydayMenu-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">日期：</label>
				<div class="col-sm-8">
					<input id="dailyDate" name="dailyDate" class="form-control" type="text">
				</div>
			</div>
			<!-- <div class="form-group">
				<label class="col-sm-3 control-label">选择菜单：</label>
				<div class="col-sm-8">
					<select id="menuId" name="menuId" class="form-control select2-hidden-accessible">
						<option th:each="menu:${menus}" th:value="${menu.menuId}" th:text="${menu.menuName}" th:disabled="${menu.status == '1'}"></option>
					</select>
				</div>
			</div> -->
			<div class="form-group">	
                <label class="col-sm-3 control-label">今天是否开餐</label>
                <div class="col-sm-8">
				    <div class="radio-box" th:each="dict : ${@dict.getType('daily_is_open')}">
						<input type="radio" th:id="${dict.dictCode}" name="isOpen" th:value="${dict.dictValue}" th:checked="${dict.isDefault == 'Y' ? true : false}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
            </div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
	   /*  var laydate = layui.laydate;
		    laydate.render({
				elem: '#dailyDate' //指定元素
			}); */
			
		layui.use('laydate', function(){
			var laydate = layui.laydate;
			//执行一个laydate实例
			laydate.render({
				elem: '#dailyDate' //指定元素
			});
		});
		
		var prefix = ctx + "dailymenu/everyday"
		$("#form-everydayMenu-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			submitHandler: function(form) {
				//$.operate.save(prefix + "/add", $('#form-everydayMenu-add').serialize());
				add();
			}
		});
		
		Date.prototype.Format = function (fmt) { 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        	return fmt;
    	} 
		
		function add() {
        	var dailyDate = $("input[name='dailyDate']").val();
        	dailyDate = new Date(dailyDate).Format("yyyy-MM-dd hh:mm:ss");
        	//alert(dailyDate);
        	var menuId = $("#menuId").val();
        	
        	var isOpen = $("input[name='isOpen']:checked").val();
        	
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "dailymenu/everyday/add",
        		data : {
        			"dailyDate": dailyDate,
        			"menuId": menuId,
        			"isOpen" : isOpen
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
	</script>
</body>
</html>
